apiready = function() {
    seajs.use(['../../V', "../../api", "../../jquery", "../../app", "../../service", "../../pop"], function(V, $api, $, $app, service, $pop) {
        var vm = {
            el: '.container',
            data: {
                is_group: false,
                order_id: 0,
                list: '',
                order_return_id: 0,
                type: 0,
                is_express: false,
                express_company: '', //--快递公司
                express_number: '', //--快递单号
                unionid: $api.getStorage("shop_unionid"),
                name: ''
            },
            methods: {
                init: function() {
                    this.getGoodsInfo();
                    this.getRefundInfo();
                    this.getExpressInfo();
                },
                //--获取商品信息
                getGoodsInfo: function() {
                    var self = this;
                    $app.ajax(service.buyGetOrderDetail, {
                        data: {
                            values: {
                                unionid: self.unionid,
                                order_id: self.order_id
                            }
                        }
                    }, function(res) {
                        console.log("goods: " + JSON.stringify(res));
                        if (res.code == 0) {
                            self.list = res.data;
                        }
                    });
                },
                //--获取退款信息
                getRefundInfo: function(et) {
                    var self = this;
                    $app.ajax(service.buyGetRefundInfo, {
                        data: {
                            values: {
                                unionid: self.unionid,
                                order_return_id: self.order_return_id
                            }
                        }
                    }, function(res) {
                        console.log("refundInfo: " + JSON.stringify(res));
                        if (res.code == 0) {
                            self.type = res.data.type;
                        }
                    });
                },
                //--提交快递信息
                submitExpressInfo: function(et) {
                    var self = this;
                    var _c = this.$refs.expressCompany.value;
                    var _n = this.$refs.expressNumber.value;
                    if (_c == '' || _n == "") {
                        $app.toast("快递信息不能为空");
                        return;
                    }
                    this.express_company = _c;
                    this.express_number = _n;
                    $app.ajax(service.buyFillInExpress, {
                        data: {
                            values: {
                                unionid: self.unionid,
                                order_id: self.order_id,
                                order_return_id: self.order_return_id,
                                express_company: self.express_company,
                                express_number: self.express_number
                            }
                        }
                    }, function(res) {
                        console.log("selectServer: " + JSON.stringify(res));
                        if (res.code == 0) {
                            self.$refs.expressInfo.style.display = 'none';
                            $pop.tip("快递信息已成功提交！");
                            self.is_express = true;
                        }
                    });
                },
                //--获取已寄信息
                getExpressInfo: function(et) {
                    var self = this;
                    $app.ajax(service.buyGetFillInExpress, {
                        data: {
                            values: {
                                unionid: self.unionid,
                                order_id: self.order_id,
                                order_return_id: self.order_return_id,
                                bs: ''
                            }
                        }
                    }, function(res) {
                        console.log("selectServer: " + JSON.stringify(res));
                        if (res.code == 0) {
                            self.express_company = res.data.express_company || '';
                            self.express_number = res.data.express_number || '';
                            self.is_express = true;
                        } else {
                            self.is_express = false;
                        }
                    });
                },
                //--联系卖家
                contactSell: function(et) {
                    var userinfo = this.list.shop_user;
                    $app.yz_chat(userinfo);
                },
                //--撤销申请
                RepealRefundApply: function(et) {
                    var self = this;
                    $pop.msg({
                        title: '温馨提示',
                        msg: '确认要撤销退款申请吗？',
                        btns: ['取消', '撤销']
                    }, function(res) {
                        if (res.index == 1) {
                            $app.ajax(service.buyUndoRefund, {
                                data: {
                                    values: {
                                        unionid: self.unionid,
                                        order_return_id: self.order_return_id
                                    }
                                }
                            }, function(res) {
                                console.log("buyDelOrder: " + JSON.stringify(res));
                                if (res.code == 0) {
                                    $pop.tip("已经撤销申请成功！", function() {
                                        api.sendEvent({
                                            name: 'buOrderMy'
                                        });
                                        $api.setTimeout(function() {
                                            api.closeWin();
                                        }, 300);
                                    });
                                } else {
                                    $pop.tip("撤销失败！");
                                }
                            });
                        }
                    });
                },
                //--修改申请
                modRefundApply: function(et) {
                    $app.openWin("buyRefundApply", {
                        type: this.type,
                        order_id: this.order_id,
                        order_return_id: this.order_return_id
                    });
                },
                //--显示填写或修改快递信息
                openFillExperss: function(et) {
                    this.$refs.expressInfo.style.display = 'block';
                },
                //--关闭填写或修改快递信息
                closeFillExperss: function(et) {
                    this.$refs.expressInfo.style.display = 'none';
                },
                //--复制
                copyOrderCode: function(et) {
                    var _txt = et.currentTarget.dataset.txt || '';
                    var clipBoard = api.require('clipBoard');
                    clipBoard.set({
                        value: _txt
                    }, function(ret, err) {
                        if (ret.status) {
                            api.toast({
                                msg: '已复制到剪贴板',
                                duration: 2000,
                                location: 'middle'
                            });
                        } else {
                            api.toast({
                                msg: ret.mst,
                                duration: 2000,
                                location: 'middle'
                            });
                        }
                    });
                },
                //--去商品详情
                goGoodsDetail: function(et) {
                    var goods_id = et.currentTarget.dataset.goodsid;
                    var is_group = et.currentTarget.dataset.group == '1' ? true : false;
                    $app.goGoodsDetail(goods_id, is_group);
                }
            },
            mounted: function() {
                var self = this;
                api.setStatusBarStyle({
                    style: 'dark',
                    color: ''
                });

                function btnKeyBack() {
                    api.sendEvent({
                        name: 'refundRepeal_'
                    });
                    $api.setTimeout(function() {
                        api.closeToWin({
                            name: self.name
                        });
                    }, 300)
                }

                //--点击上面按钮返回
                $api.addEvt($api.dom('#btn-back-new'), 'click', function() {
                    btnKeyBack();
                });

                //--返回键
                api.addEventListener({
                    name: 'keyback'
                }, function(ret, err) {
                    btnKeyBack();
                });
                //--右滑
                api.addEventListener({
                    name: 'swiperight'
                }, function(ret, err) {
                    btnKeyBack();
                });

            },
            created: function() {
                this.order_id = api.pageParam.order_id || '';
                this.order_return_id = api.pageParam.order_return_id || '';
                this.name = api.pageParam.name || api.pageParam.prve;
                this.init();
            }
        };
        //var shopVue = new Vue(vm);
        var even = function() {

        };
        var newVue = new Vue(vm);
        even();

    })
}
